<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org./1999/xhtml">
<head>
<meta http-equiv="content-Type" content="textml; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE; chrome=1"/>
<meta name="viewport" content="width=device-width; initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>鲜店  天天新鲜！</title>
<link  href="/css/shop.948.css" media="screen" rel="stylesheet" type="text/css"/>
<script type="text/javascript"  src="/js/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
function showShareBox(){
	//if(true == checkMobileNumber()) {
		$('.remark_box').css('display','block');
	//}
}
function hideShareBox() {
	//if(true == checkMobileNumber()) {
		$('.remark_box').css('display','none');
	//}
}
</script> 
</head>
<body class="layout_body">
<?php 
	$productList = $this->orderDetails->itemList;
	$productListObj = $productList[0];
	$skuname = $productListObj->skuname;
	$feature = $productListObj->feature;
	$price = $productListObj->price;
	$cashBack = round($price*0.05);
	$imgurl = $productListObj->imgurl;
	$shopProductId = $productListObj->shopProductId;
	if(!empty($skuname)&& !empty($price)){
		$title = '我买了好吃到爆的'.$skuname.'，还得了'.$cashBack.'元返现哦，亲你也来试试吧';
	}else{
		$title = '鲜店，新鲜菜，放心肉！';
	}
	if(!empty($feature)){
		$desc = $feature;
	}else{
		$desc = '我已在鲜店下单，还得了现金返现，亲你也来试试吧！';
	}
	if(!empty($imgurl)){
		$skuIcon = $imgurl;
	}else{
		$skuIcon = 'http://'.$this->baseUrl.'/images/hb_logo4.jpg';
	}
	if(!empty($shopProductId)){
		$link = 'http://'.$this->baseUrl.'/presalesku/details?id='.$shopProductId;
	}else{
		$link = 'http://'.$this->baseUrl.'?tab=presale';
	}
?>
<img src="<?php echo $skuIcon;?>" width="0" height="0" />
<div class="layout_content">
<!--<div id="hb_share_holder">
  <div id="hb_duihua">  
    <span>Duang~点击右上角分享朋友圈领现金券！</span>
 </div>
<div class="remark_box" style="display:none" onclick="javascript:hideShareBox();return false;"><div class="box_img"><img src="/images/share_remark.png" width="100%"  class="open_remark"></div></div>
</div>-->
<div class="bg_color" style="background-color:white;">
<div style="width:80%;margin:0px auto;margin-top:15px;padding:0px;position:relative;top:5px;">
	<img style="width:100%;padding:0px;margin:0px;" src="/images/jiao.jpg">
</div>
<div style="background-color:#F64444;text-align:center;width:84%;margin:0px auto;color:white;padding:10px 0px;border-radius:4px;">  
点击分享订单至朋友圈立刻返现
</div>
<?php 
if($this->followed){//未关注
	echo '<div style="margin:0px auto;width:80%;text-align:center;margin-top:20px;">
			亲，您还没有关注微信号哦！<br>
			<img style="width:100%;" src="/images/erweima3.jpg">
		 </div>
		 ';
}else{
	echo '
		  <div style="margin:20px 0px;text-align:center;">
		  	<img style="width:30%;margin:0px auto;" src="/images/xiaoluobo.png">
		  </div>
		  <a href="/order/list"><div style="text-align:center;">在个人中心可查看详情</div></a>
		';
}


if (isset($this->result)) {
  $result = $this->result;
  $mobile = $this->mobile;
  $discount = $this->discount;
  $orderId = $this->orderId;
  $openId = $this->openId; 
  $signPackage = new Application_Model_GetSignPackage();
  $req = $signPackage->getSignPackage();
  if ($result == 'success') {
  echo ' 
    <div id="hb_dialog" >
    <span><div class="hongb_amount">￥'.$discount.'</div><div class="hb_hbj">现金券</div>
	<div class="hongb_mobile">已放入您的账户</div>
	</span>
  </div>
    <div id ="hb_show_notice">
      <form action="/" method="get">	
        <p><input id="hb_redeem_btn" class="roundCorner" name="submit" type="submit" value="立刻使用"/></p>
        <!--<p><input id="hb_share_btn" class="roundCorner" type="button" onclick="javascript:showShareBox();return false;" value="邀请好友一起领"/></p>-->
      </form>
    </div>
    <div class="clearFloat"></div>
    ';
  } else {
    echo '
	  <div id="linghb" >
			<span></span>
	  </div> 
    <div id ="hb_input_area">
      <form action="/share/" method="post">
        <p><input id="hb_mobile" class="roundCorner" name="mobile" type="hidden" placeholder="请输入手机号" value="'.$mobile.'"/></p>
       <!-- <p><input type="button" id="hb_redeem_btn"  class="roundCorner" name="submit" onclick="javascript:gotoPresale();return false;" value="我也来领券"/></p>-->
        <!--<p><input id="hb_share_btn" class="roundCorner" type="button" onclick="javascript:showShareBox();return false;" value="邀请好友一起领"/></p>-->
		<input type="hidden"  id="orderId" value="'.$orderId.'">
		<input type="hidden"  name="openId" value="'.$openId.'">
      </form>
    </div>
    <div class="clearFloat"></div>
	';
    if ($result == 'wrong number') {
      echo '<script type="text/javascript">$(document).ready(function(){alert("请输入正确的手机号！");});</script>
	  ';
	  
    } else if ($result == 'voucher exists') {
      echo '<script type="text/javascript">$(document).ready(function(){alert("您已领取该现金券，请在微信中关注鲜店后使用！");});</script>';
    }
  }
}

	// if (count($this->VoucherList) > 0) {
		// echo'<div class="line mc"><i class="l">★</i><span>领到的现金券</span><i class="r">★</i></div>';
		// foreach($this->VoucherList as $Voucher){
			// echo '
			// <div style="width:80%;margin: 0 auto;">
				  // <div class="hongnbao">
				  // <div class="head_sty"><img src="'.$Voucher->avatar.'"/>
					// <span>'.$Voucher->nickname.'</span></br>
				  // </div>
				 // <div class="time_sty">
					// <p>'.$Voucher->inserttime.'</p> 
				 // </div>
				  // <div class="amount_sty" style="margin-left:210px;">
					// <p>'.$Voucher->discount.'元</p>
				 // </div>
				 // </div>
				 // </div>
			// ';
		// }
	// } else {
		
	// }
?>
<!--
<div class="line mc" style="margin-top:50px"><i class="l">★</i><span>活动规则</span><i class="r">★</i></div>
  <div id="hb_share_rule">
	<div class="hb_hg"><div class="hb_sxu">1</div>
	<div class="hb_neirong">本活动时间2015/8/1至2015/8/31</div></div>
	
	<div class="hb_hg">	<div class="hb_sxu">2</div>
	<div class="hb_neirong">使用现金券时的下单手机号需为抢现金券时使用的手机号</div></div>
	
	<div class="hb_hg">	<div class="hb_sxu">3</div>
	<div class="hb_neirong">一个手机号码只能参与一次 </div></div>
	
	<div class="hb_hg">	<div class="hb_sxu">4</div>
	<div class="hb_neirong">现金券仅限在线支付使用，每张订单仅限使用一个现金券，现金券不找零、不兑现</div></div> </br>
	
	<div class="hb_hg">	<div class="hb_sxu">5</div>
	<div class="hb_neirong"> 现金券有效期及使用说明请参见现金券详情</div></div>

	<div class="hb_hg">	<div class="hb_sxu">6</div>
	<div class="hb_neirong">鲜店保留法律范围内允许的对活动的最终解释权</div></div>
  </div>
-->
</div>
</div>
<script type="text/javascript">
	var title = '<?php echo $title;?>';
	var desc =  '<?php echo $desc;?>';
	// var link = 'http://shop.renrencaichang.com/share?orderId=<?php echo $orderId?>';
	var link ='<?php echo $link;?>';
	var imgurl = '<?php echo $skuIcon;?>';
	function gotoPresale() {
		location.href = '/?tab=presale';
	}
  	function checkMobileNumber() {
		var mobile = $('#hb_mobile').val();
		if (typeof(mobile) == 'undefined') {
			return true;
		}
		if (mobile.length == 0) {
			$('.remark_box').css('display','none');
			alert('亲，请输入手机号领用现金券哦！');
			return false;
		}
		var myreg = /1[34578]{1}\d{9}$/;
		if (mobile.length!=11 || !myreg.test(mobile) ) {
			$('.remark_box').css('display','none');
			alert('您的手机号码输入有误！');
			return false;
		}
		return true;
	}
	function postSharingVoucher(res) {
		var mobile = $('#hb_mobile').val();
		$('.remark_box').css('display','none');
		if (typeof(mobile) == 'undefined') {
			return true;
		}
		var orderId = $('#orderId').val();
		$.ajax({
		  type: "post", 
		  url : "/share/result/", 
		  dataType: 'json',
		  data: {'mobile':mobile,'orderId':orderId},
		  success: function(info){
				if(info.msg=='fail'){
					alert("亲，您已领取过现金券或是您未关注鲜店公众号，要先关注后再分享哦！");
				}else{
					alert("亲，现金券已发放,请点击我的现金券查收,未收到请与客服联系");
					var link = 'http://<?php echo $this->baseUrl;?>/share?orderId='+orderId+'&mobile='+mobile;
					location.assign(link);
				}
		  }
		});
	}
    wx.config({
        debug: false,
        appId:      '<?php echo $req["appId"];?>',
        timestamp:  '<?php echo $req["timestamp"];?>',
        nonceStr:   '<?php echo $req["nonceStr"];?>',
        signature:  '<?php echo $req["signature"];?>',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo'
        ]
    });
	// wx.error(function(res){
		// alert(res.errMsg);
	// });
// success：接口调用成功时执行的回调函数。
// fail：接口调用失败时执行的回调函数。
// complete：接口调用完成时执行的回调函数，无论成功或失败都会执行。
// cancel：用户点击取消时的回调函数，仅部分有用户取消操作的api才会用到。
// trigger: 监听Menu中的按钮点击时触发的方法，该方法仅支持Menu中的相关接口。
// 监听“分享到朋友圈”
    wx.ready(function () {
        wx.onMenuShareTimeline({//分享朋友圈
            title: title,
			desc: desc,
            link: link,
			imgUrl: imgurl,
            trigger: function (res) {
				return checkMobileNumber();
            },
            success: function (res) {
				postSharingVoucher(res);
            },
            cancel: function (res) {
                alert('已取消');
            },
            fail: function (res) {
                alert('wx.onMenuShareTimeline:fail: '+JSON.stringify(res));
            }
        });
        wx.onMenuShareAppMessage({//分享给朋友
            title: title,
			desc: desc,
            link: link,
            imgUrl: imgurl,
            trigger: function (res) {
				return checkMobileNumber();
            },
            success: function (res) {	
				postSharingVoucher(res);
            },
            cancel: function (res) {
                alert('已取消');
            },
            fail: function (res) {
                alert('wx.onMenuShareAppMessage:fail: '+JSON.stringify(res));
            }
        });
    });
	
	function getWinWidth(){
		return $('#hb_share_holder').width();
	}

	var h = getWinWidth();
	$('#hb_share_holder').css('height',h*458/640);

	$(window).resize(function() {
		var h = getWinWidth();
		$('#hb_share_holder').css('height',h*458/640);
	});
</script>
</body>
</html>
